<?php

	$tim = new Tim($_GET['id']);

?>


        	<div class="fullPageBox">
            	<div class="teamTopInfo">
	            	<img src="media/teams/header/<?php echo $tim->slika; ?>" />
                    <h2 class="teamName"><?php echo $tim->ime; ?></h2>
                </div>
                
            </div><!-- end of slideshow -->
            
            
            <div class="twoCollumns">
            	<div class="leftCollumn">

                	<div class="leftBox">
                    	<div class="rosterHolder">
                        
                        <?php
						
						$tim->getRoster();
						foreach($tim->roster as $roster) {
							$pozicije = "";
							if(count($roster->pozicije)) {
								foreach ($roster->pozicije as $poz) {
									$pozicije .= $poz . ", ";
								}
								$pozicije = "(".substr_replace($pozicije ,"",-2).")";
							}
							echo "
							<div class='teamRoster'>
								<a href='player/". $roster->id ."/". $roster->ime ."-". $roster->prezime ."'><img src='media/players/" . $roster->slika . "' /></a><br />
							";
							if ($roster == $tim->getKapiten())	echo "<span class='teamCaptain'>C</span>";
							echo "
								<a href='player/". $roster->id ."/". $roster->ime ."-". $roster->prezime ."'>". $roster->ime ."<br />". $roster->prezime ."</a><br />
								<span>". $pozicije ."</span>
							</div>
							";
						}
						?>
                        
                        </div>
                    </div>
                    <h3 class="smallBoxTitle"><a href="#">Roster</a></h3>
                    
                	<div class="leftBox">
                    	<table class="tabela teamStatistics" cellpadding="0" cellspacing="0">
                        <thead>
                            <tr>
                            	<td>#</td>
                            	<td class="statsPlayerName">Player</td>
                            	<td>FT</td>
                            	<td>2PT</td>
                            	<td>3PT</td>
                            	<td>PTS</td>
                            	<td>ASS</td>
                            	<td>DRB</td>
                            	<td>ORB</td>
                            	<td>BLK</td>
                            	<td>STL</td>
                            	<td>FLS</td>
                            	<td>IND</td>
                            </tr>
                        </thead>
                        <tbody>
                        
                        <?php 
						
							foreach($tim->roster as $player) {
								$player->getAllStats();
								$player->calculateTotalStats();
						?>
                        
                        	<tr>
                            	<td class="statsOdd"><?php echo $player->dres; ?></td>
                            	<td class="statsPlayerName"><a href="player/<?php echo $player->id; ?>/<?php echo $player->ime."-".$player->prezime; ?>"><?php echo $player->ime; ?> <?php echo $player->prezime; ?></a></td>
                            	<td class="statsOdd"><?php echo $player->totalStats->ft; ?>/<?php echo $player->totalStats->ft+$player->totalStats->mft; ?></td>
                            	<td><?php echo $player->totalStats->fg; ?>/<?php echo $player->totalStats->fg+$player->totalStats->mfg; ?></td>
                            	<td class="statsOdd"><?php echo $player->totalStats->threept; ?>/<?php echo $player->totalStats->threept+$player->totalStats->mtp; ?></td>
                            	<td><?php echo $player->totalStats->pts; ?></td>
                            	<td class="statsOdd"><?php echo $player->totalStats->ast; ?></td>
                            	<td><?php echo $player->totalStats->drbd; ?></td>
                            	<td class="statsOdd"><?php echo $player->totalStats->orbd; ?></td>
                            	<td><?php echo $player->totalStats->blk; ?></td>
                            	<td class="statsOdd"><?php echo $player->totalStats->stl; ?></td>
                            	<td><?php echo $player->totalStats->licne; ?></td>
                            	<td class="statsOdd"><?php echo $player->totalStats->BLindex; ?></td>
                            </tr>
                        <?php 
							}							
						?>
                        
                        <?php $tim->stats = $tim->getTotalStats(); ?>
                            <tr class="statsTeamTotal">
                            	<td class="statsOdd"></td>
                            	<td class="statsPlayerName">Team Total:</td>
                            	<td class="statsOdd"><?php echo $tim->stats->ft; ?>/<?php echo $tim->stats->ft+$tim->stats->mft; ?></td>
                            	<td><?php echo $tim->stats->fg; ?>/<?php echo $tim->stats->fg+$tim->stats->mfg; ?></td>
                            	<td class="statsOdd"><?php echo $tim->stats->threept; ?>/<?php echo $tim->stats->threept+$tim->stats->mtp; ?></td>
                            	<td><?php echo $tim->stats->pts; ?></td>
                            	<td class="statsOdd"><?php echo $tim->stats->ast; ?></td>
                            	<td><?php echo $tim->stats->drbd; ?></td>
                            	<td class="statsOdd"><?php echo $tim->stats->orbd; ?></td>
                            	<td><?php echo $tim->stats->blk; ?></td>
                            	<td class="statsOdd"><?php echo $tim->stats->stl; ?></td>
                            	<td><?php echo $tim->stats->licne; ?></td>
                            	<td class="statsOdd"><?php echo $tim->stats->BLindex; ?></td>
                            </tr>
                            
                            
                            <tr class="statsTeamTotal">
                            
                            <?php $tim->getSchedule(); ?>
							<?php $tim->stats = $tim->getAverageStats(); ?>
                            	<td class="statsOdd"></td>
                            	<td class="statsPlayerName">Season Average:</td>
                            	<td class="statsOdd"><?php echo $tim->stats->ft == 0 ? 0 : round(100*($tim->stats->ft/($tim->stats->ft+$tim->stats->mft)), 2); ?>%</td>
                            	<td><?php echo $tim->stats->fg == 0 ? 0 : round(100/($tim->stats->mfg/$tim->stats->fg + 1), 2); ?>%</td>
                            	<td class="statsOdd"><?php echo $tim->stats->threept == 0 ? 0 : round(100/($tim->stats->mtp/$tim->stats->threept + 1), 2); ?>%</td>
                            	<td><?php echo $tim->stats->pts; ?></td>
                            	<td class="statsOdd"><?php echo $tim->stats->ast; ?></td>
                            	<td><?php echo $tim->stats->drbd; ?></td>
                            	<td class="statsOdd"><?php echo $tim->stats->orbd; ?></td>
                            	<td><?php echo $tim->stats->blk; ?></td>
                            	<td class="statsOdd"><?php echo $tim->stats->stl; ?></td>
                            	<td><?php echo $tim->stats->licne; ?></td>
                            	<td class="statsOdd"><?php echo $tim->stats->BLindex; ?></td>
                            </tr>
                        </tbody>
                        </table>
                    </div>
                    <h3 class="smallBoxTitle"><a href="#">Team Stats</a></h3>
                    
                </div>
                
                <div class="rightCollumn">
                
                	<div class="smallBox">
                    	<table class="tabela" cellpadding="0" cellspacing="0">
                        <tbody>
                        
                        <?php 
							if (count($tim->schedule)) {							
							foreach ($tim->schedule as $mec) {
								$protivnik = NULL;
								if ($mec->domacin->id == $tim->id) {
									$protivnik = clone $mec->gost;
								}
								else {
									$protivnik = clone $mec->domacin;
								}
								if($mec->odigrana == 1) {
									$protivnik->getRoster();
									$protivnik->stats = $protivnik->getMatchStats($mec->id);
									$tim->stats = $tim->getMatchStats($mec->id);
								}
						?>
                        
                        	<tr>
                            	<td class="tabelaPosition">vs</td>
                            	<td class="tabelaCrest"><img src="media/teams/logo/<?php echo $protivnik->grb; ?>" height="25" /></td>
                            	<td class="tabelaName"><a href="team/<?php echo $protivnik->id; ?>/<?php echo str_replace(" ", "-", $protivnik->ime); ?>"><?php echo $protivnik->ime; ?></a></td>
                                
                                
								<?php if($mec->odigrana) {?>
                                <td class="tabelaPoints">
                                <a href="match/<?php echo $mec->id; ?>"><?php echo $tim->stats->pts; ?>-<?php echo $protivnik->stats->pts; ?></a>
                                </td>
                                <?php } ?>
                                <?php if(!$mec->odigrana) {?>
                                <?php $round = new Round($mec->kolo); ?>
                                <td class="tabelaSchedule"><?php echo $round->datum; ?> u <?php echo $mec->vreme; ?></td>
                                <?php } ?>
                                
                            </tr>
                        <?php 
							}
							}
						?>
                        
                        </tbody>
                        </table>
                    </div>
                    <h3 class="smallBoxTitle"><a href="#">Results &amp; Schedule</a></h3>
                    
                	<div class="smallBox">
                    	<table class="tabela" cellpadding="0" cellspacing="0">
                        <thead>
                            <tr>
                            	<td>#</td>
                            	<td>Tim</td>
                            	<td></td>
                            	<td>Pt</td>
                            </tr>
                        </thead>
                        <tbody>
                    <?php
						$tabela = new Standings(1, 1);
						$tabela->getTeams();
						$tabela->getTeamsStats();
						$tabela->sortTeams();
						
						$pozicija = 1;
						
						foreach($tabela->tabela as $tim2) {
						
					?>
                        	<tr<?php if ($tim2->id == $tim->id) { echo " class='statsOdd' "; } ?>>
                            	<td class="tabelaPosition"><?php echo $pozicija++; ?></td>
                            	<td class="tabelaCrest"><img src="media/teams/logo/<?php echo $tim2->grb; ?>" height="25" /></td>
                            	<td class="tabelaName"><a href="team/<?php echo $tim2->id; ?>/<?php echo str_replace(" ", "-", $tim2->ime); ?>"><?php if ($tim2->id == $tim->id) { echo "<strong>".$tim2->ime."</strong>"; } else echo $tim2->ime; ?></a></td>
                            	<td class="tabelaPoints"><?php echo $tim2->brojPoena; ?></td>
                            </tr>
                    <?php
						}
					?>
                        </tbody>
                        </table>
                    </div>
                    <h3 class="smallBoxTitle"><a href="#">Tabela</a></h3>
                    
